home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_085 / rawio / sendpacket.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  70 lines

  1. /*
  2.  *    Sendpacket.c 
  3.  *
  4.  *  An invaluable addition to your Amiga.lib file. This code sends a packet
  5.  * the given message port. This makes working around DOS lots easier.
  6.  * 
  7.  * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
  8.  * however that you may wish to add it to Amiga.Lib, to do so, compile it
  9.  * and say 'oml lib:amiga.lib -r sendpacket.o' 
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/ports.h>
  14. #include <exec/memory.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17.  
  18. /*
  19.  * Function - SendPacket written by Phil Lindsay, Carolyn Scheppner, and
  20.  * Andy Finkel. This function will send a packet of the given type to the
  21.  * Message Port supplied.
  22.  */
  23.  
  24. long
  25. SendPacket(pid,action,args,nargs)
  26.  
  27. struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
  28. long action,          /* packet type ... (what you want handler to do )   */
  29.      args[],          /* a pointer to a argument list */
  30.      nargs;           /* number of arguments in list  */
  31. {
  32.   struct MsgPort        *replyport;
  33.   struct StandardPacket *packet;
  34.  
  35.   long  count, *pargs, res1;
  36.  
  37.   replyport = (struct MsgPort *) CreatePort(NULL,0);
  38.   if(!replyport) return(0);
  39.  
  40.   /* Allocate space for a packet, make it public and clear it */
  41.   packet = (struct StandardPacket *) 
  42.     AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
  43.   if(!packet) {
  44.     DeletePort(replyport);
  45.     return(0);
  46.   }
  47.  
  48.   packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  49.   packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
  50.   packet->sp_Pkt.dp_Port         = replyport;
  51.   packet->sp_Pkt.dp_Type         = action;
  52.  
  53.   /* copy the args into the packet */
  54.   pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
  55.   for(count=0;count < nargs;count++) 
  56.     pargs[count]=args[count];
  57.  
  58.   PutMsg(pid,packet); /* send packet */
  59.  
  60.   WaitPort(replyport);
  61.   GetMsg(replyport); 
  62.  
  63.   res1 = packet->sp_Pkt.dp_Res1;
  64.  
  65.   FreeMem(packet,(long)sizeof(struct StandardPacket));
  66.   DeletePort(replyport); 
  67.  
  68.   return(res1);
  69. }
  70.